# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_realname=manim
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.10.0
pkgrel=1
pkgdesc="Animation engine for explanatory math videos (community edition) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.manim.community'
license=('MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-ffmpeg"  
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-click-default-group"
  "${MINGW_PACKAGE_PREFIX}-python-colour"
  "${MINGW_PACKAGE_PREFIX}-python-numpy"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
  "${MINGW_PACKAGE_PREFIX}-python-scipy"
  "${MINGW_PACKAGE_PREFIX}-python-tqdm"
  "${MINGW_PACKAGE_PREFIX}-python-pydub"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
  "${MINGW_PACKAGE_PREFIX}-python-cairo"
  "${MINGW_PACKAGE_PREFIX}-python-manimpango"
  "${MINGW_PACKAGE_PREFIX}-python-networkx"
  "${MINGW_PACKAGE_PREFIX}-python-decorator"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-watchdog"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl-window"
  "${MINGW_PACKAGE_PREFIX}-mapbox-earcut"
  "${MINGW_PACKAGE_PREFIX}-python-cloup"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-screeninfo"
)
optdepends=("${MINGW_PACKAGE_PREFIX}-texlive-scheme-medium: For LaTeX support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(
  "${_realname}-${pkgver}.tar.gz"::"https://github.com/ManimCommunity/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
)
sha512sums=('a382850a3e8b8c40390e20240e0853f58d0b7f3b36e6a354110c6dff63e0633eb45fe6d2fb7b505b34fb6588f0f309bc27c0504e13f7c625f31e6b63fa843867')

prepare() {
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
  cd "python-build-${CARCH}"
  sed -i 's/screeninfo>=0.6.7,<0.7.0/screeninfo/' setup.py
}

build() {  
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -i 's/\#\!.*//' $_f
  done
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 LICENSE.community "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.community"
}
